package cn.btks.resultintegration.achievements.controller;

import cn.btks.commonserver.result.MenuSourceEnum;
import cn.btks.commonserver.result.ResultState;
import cn.btks.commonserver.result.StateInfo;
import cn.btks.commonserver.result.SystemLogEnum;
import cn.btks.commonserver.valid.SystemLog;
import cn.btks.resultintegration.achievements.pojo.Achievements;
import cn.btks.resultintegration.achievements.pojo.AchievementsFileTemp;
import cn.btks.resultintegration.achievements.service.AchievementsFileTempService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.MultiValueMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Author lijun
 * @Date 2021/2/23 15:58
 */
@Slf4j
@RestController
@RequestMapping("api/v1.0/resultIntegration/achievements/temp")
@Api(tags = "成果整合模块")
@Validated
public class AchievementsFileTempController {

    @Autowired
    AchievementsFileTempService achievementsFileTempService;

    @SystemLog(type = SystemLogEnum.ZIP_LOG,moduleMessage = MenuSourceEnum.MENU_RESULT)
    @GetMapping("/verify/fileTemp/zipFileByCityId/{cityId}")
    @ApiOperation("压缩某师的成果文件")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "cityId", value = "师ID", required = true, dataType = "long"),
            @ApiImplicitParam(paramType = "header", name = "token", value = "token密匙", required = true, dataType = "string")
    })
    public ResultState zipFileByCityId(@PathVariable("cityId") Long cityId, HttpServletRequest request) {
        return achievementsFileTempService.zipFileByCityId(cityId, request);
    }

    @SystemLog(type = SystemLogEnum.ZIP_LOG,moduleMessage = MenuSourceEnum.MENU_RESULT)
    @GetMapping("/verify/fileTemp/zipFileCategory/{fileCategoryId}")
    @ApiOperation("压缩某类型的成果文件")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "fileCategoryId", value = "文件类型ID", required = true, dataType = "long"),
            @ApiImplicitParam(paramType = "header", name = "token", value = "token密匙", required = true, dataType = "string")
    })
    public ResultState zipFileCategory(@PathVariable("fileCategoryId") Long fileCategoryId, HttpServletRequest request) {
        return achievementsFileTempService.zipFileCategory(fileCategoryId, request);
    }

    @SystemLog(type = SystemLogEnum.UPDATE_LOG,moduleMessage = MenuSourceEnum.MENU_RESULT)
    @PutMapping(value = "/fileTemp/updateEvidenceFiles/{achievementTempId}",headers = "content-type=multipart/form-data")
    @ApiOperation(value = "更新佐证材料", notes = "更新佐证材料")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "achievementTempId", value = "成果ID", required = true, dataType = "long"),
            @ApiImplicitParam(paramType = "header", name = "token", value = "token", required = true, dataType = "string")
    })
    public ResultState updateEvidenceFiles(@PathVariable("achievementTempId") Long achievementTempId, @ApiParam(name = "多文件", value = "multipartFile", required = true) MultipartHttpServletRequest multipartVectorFiles, HttpServletRequest request){
        MultiValueMap<String, MultipartFile> map = multipartVectorFiles.getMultiFileMap();
        List<MultipartFile> list = map.get("multipartFile");// 获取到文件的列表
        return achievementsFileTempService.updateEvidenceFiles(achievementTempId, list, request);
    }
}
